# scripts/build-release.sh
#!/bin/bash
source ./scripts/config.sh

cd $FFMPEG_SRC || exit 1
make clean

echo "🚀 配置 FFmpeg 发布版 (arm64-v8a) ..."

./configure \
  --prefix=$RELEASE_PREFIX \
  --target-os=android \
  --arch=$ARCH \
  --cpu=$CPU \
  --cc=$CC \
  --cxx=$CXX \
  --strip=$STRIP \
  --enable-cross-compile \
  --cross-prefix=$TOOLCHAIN/bin/aarch64-linux-android- \
  --pkg-config=pkg-config \

  # --- 禁用无关程序 ---
  --disable-doc \
  --disable-programs \
  --disable-ffmpeg \
  --disable-ffplay \
  --disable-ffprobe \
  --disable-symver \

  # --- 核心功能 ---
  --disable-everything \
  --enable-decoders \
  --enable-encoders \
  --enable-demuxer=h264,hevc,mpegts,mp4,aac,wav,pcm_s16le,rawvideo,mov,avi \
  --enable-muxer=h264,hevc,mpegts,mp4,aac,wav,pcm_s16le,rawvideo,mov,avi \
  --enable-parser=h264,h265,aac,mpeg4video,mpegvideo \
  --enable-protocol=file,http,https,rtmp,rtsp,rtp \
  --enable-filter=scale,resample,crop,pad,format,aformat \

  # --- 性能优化 ---
  --enable-gpl \
  --enable-nonfree \
  --enable-version3 \
  --enable-optimizations \
  --enable-pthreads \
  --enable-asm \
  --enable-inline-asm \
  --enable-neon \
  --enable-hardcoded-tables \
  --enable-small \
  --optflags='-O2 -fno-math-errno -fno-signed-zeros -fno-trapping-math' \
  --extra-cflags='-fPIC -fdata-sections -ffunction-sections' \
  --extra-ldflags='-s -Wl,--gc-sections' \

  # --- 输出类型 ---
  --disable-shared \
  --enable-static \

  || exit 1

make -j$(nproc) && make install
echo "✅ 发布版构建完成：$RELEASE_PREFIX"